<?php


namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Dashboard extends model
{
    // 表名
    protected $name = 'plan';

    //获取审核权限数组
    public function getPassRoleArr()
    {
        //文章 article
        //安全检查 safecheck
        //任务 task
        //计划 plan
        $tableArr = ['article','safecheck','task','plan'];
        foreach($tableArr as $v){
            $arr[$v] = $this->getPassRoleIdArr($v);
        }
        return $arr;

    }


    //获取审核权限的id数组
    protected function getPassRoleIdArr($str){
        $strPass = $str.'/pass';
        $strRebut = $str.'/rebut';
        $arr = [];
        $arr[] = AuthRule::where('name',$strPass)->value('id');
        $arr[] = AuthRule::where('name',$strRebut)->value('id');
        return $arr;
    }


    public function checkRole($a,$group_id){
        //获取角色的权限
        $roleStr = AuthGroup::where('id',$group_id)->value('rules');
        if($roleStr == '*'){
            return true;
        }
        $roleArr = explode(',',$roleStr);
        foreach($a as $v){
            if(!in_array($v,$roleArr)){
                return false;
            }
        }
        return true;
    }


    //获取审核状态
    public function getPassStat($str)
    {
        switch ($str)
        {
            case 0:
                $str = '审核中';
                break;
            case 1:
                $str = '<span style="color:green;">通过</span>';
                break;
            case 2:
                $str = '<span style="color:red;">驳回</span>';
                break;
            default:
                $str = '审核中';
        }
        return $str;
    }

}